package com.study.common.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.study.common.utils.DateUtils;
import com.study.common.utils.ServletUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author nizhihao
 * @version 1.0.0
 * @date 2023/10/31 11:25
 */
@Slf4j
public class DateConvert implements Converter<Date> {

    @Override
    public WriteCellData<String> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String timeZone = ServletUtils.getRequest().getHeader("Time-Zone");
        return new WriteCellData<>(DateUtils.convertToTimeZoneString(value, timeZone));
    }

}
